import sim, sim_items, main
from util import *
import random

class ReinforcedPrefix(sim_items.Prefix):
    """
    "reinforced" prefix boosts armor by increasing its PV or EV (whichever would
    normally be greater) by 1-3 points. 
    """
    def __init__(self):
        super(ReinforcedPrefix, self).__init__(
            "reinforced", # name
            "Whoever crafted this %(wearable)s evidently used above-average "
            "material and paid great attention to reinforcing standard "
            "weak points."
        )

    def initialize(self, wearable):
        if not isinstance(wearable, sim_items.Armor):
            raise ValueError('Tried to apply %r to non-armor item: %r' % (self,
                wearable))

        super(ReinforcedPrefix, self).initialize(wearable)
        self.bonus = random.randint(1,3) 
        if self.wearable.bonuses['evMod'] > self.wearable.bonuses['pvMod']:
            self.affectedMod = 'evMod'
        else:
            self.affectedMod = 'pvMod'
            
        self.wearable.bonuses.update({
            self.affectedMod: \
                    self.wearable.bonuses[self.affectedMod] + self.bonus
        })

    def remove(self, wearable):
        super(ReinforcedPrefix, self).remove(wearable)
        wearable.bonuses.update({
            self.affectedMod: \
                    self.wearable.bonuses[self.affectedMod] - self.bonus
        })

#========================================
thingClass = ReinforcedPrefix

